//
//  BindingPhoneTableViewCell.m
//  EasyToTesco2.0
//
//  Created by 袖手旁觀 on 16/6/16.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "BindingPhoneTableViewCell.h"

#define LeftMargin 8

@implementation BindingPhoneTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setUpBindingPhoneTableViewCell];
    }
    
    return self;
}

- (void)setUpBindingPhoneTableViewCell {
    
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.contentMode = UIViewContentModeCenter;
    self.leftImageView = imageView;
    [self.contentView addSubview:imageView];
    
    UITextField *textField = [[UITextField alloc] init];
//    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.font = [UIFont systemFontOfSize:13];
    self.textField = textField;
    textField.keyboardType = UIKeyboardTypeNumberPad;
    [self.contentView addSubview:textField];
    
    UILabel *rightLabel = [[UILabel alloc] init];
    rightLabel.font = [UIFont systemFontOfSize:15];
    rightLabel.font = [UIFont fontWithName:@ "Arial Rounded MT Bold"  size:(15.0)];
    rightLabel.hidden = YES;
    [self.contentView addSubview:rightLabel];
    self.rightLabel = rightLabel;
    
    UIButton *button = [[UIButton alloc] init];
    [button setBackgroundColor:DEFAULT_COLOR];
    button.layer.cornerRadius = 5;
    button.hidden = YES;
    button.layer.masksToBounds = YES;
    button.titleLabel.font = [UIFont systemFontOfSize:13];
    [button setTitle:@"获取验证码" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(didClickObtainButton:) forControlEvents:UIControlEventTouchUpInside];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.rightButton = button;
    [self addSubview:button];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY);
        make.left.equalTo(self.mas_left).with.offset(LeftMargin * 2);
        make.height.mas_equalTo(self.Height - LeftMargin);
        make.width.mas_equalTo(self.Height);
    }];
    
    [textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(imageView.mas_centerY);
        make.left.equalTo(imageView.mas_right).with.offset(LeftMargin * 2);
        make.height.mas_equalTo(self.Height - LeftMargin);
        make.width.mas_equalTo(self.width/2 + 40);
    }];
    
    [rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(imageView.mas_centerY);
        make.left.equalTo(imageView.mas_right).with.offset(LeftMargin * 2);
        make.height.mas_equalTo(self.Height);
        make.width.mas_equalTo(self.width/2 + 50);
    }];
    
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(textField.mas_centerY);
        make.right.equalTo(self.mas_right).with.offset(-LeftMargin*2);
        make.width.mas_equalTo(self.width/4);
        make.height.mas_equalTo(self.Height/2 + 10);
    }];
}

- (void)didClickObtainButton:(UIButton *)button {
    
    if ([self.delegate respondsToSelector:@selector(didClickYanZhengMaButton:)]) {
        [self.delegate didClickYanZhengMaButton:button];
    }
    
}

@end
